import os
from subprocess import Popen, PIPE


def use_popen():
    process = Popen([".venv/scripts/python", "-m", "nuitka",
                     "--standalone",
                     "PalToolsGUI.py",
                     "--output-dir=dest",
                     "--enable-plugin=pyside6",
                     "--include-data-dir=images=images",
                     "--include-data-dir=html=html",
                     "--windows-icon-from-ico=images/PalTools.ico",
                     "--windows-console-mode=disable"], stdout=PIPE, stderr=PIPE,
                    text=True, encoding='gbk', bufsize=1, universal_newlines=True)
    while True:
        output = process.stdout.readline()
        if output == '' and process.poll() is not None:
            break
        if output:
            print(f"stdout:{output.strip()}")

        error = process.stderr.readline()
        if error:
            print(error.strip())


if __name__ == "__main__":
    os.system("nuitka --standalone PalToolsGUI.py --output-dir=dest --enable-plugin=pyside6 --include-data-dir=images=images --include-data-dir=html=html --windows-icon-from-ico=images/PalTools.ico --follow-imports --windows-console-mode=disable")
